package autoteam.ui.dialogs;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class PlayerEditor extends AutoTeamDialog
{
	private static final long serialVersionUID = 3999440758400887037L;

	private JButton changeButton = new JButton("Change");
	private JButton cancelButton = new JButton("Cancel");

	String[] DBteams =
	{ "Bunny", "Fox", "Lynx", "Clevland Steamers" };

	private JTextField playerField;
	private JComboBox teams;
	private JTextField leagueField;
	private JTextField sportField;

	public PlayerEditor(JFrame dialogOwner)
	{
		super(dialogOwner);

		this.setTitle("Edit Player");
		this.setDialogSize(new Dimension(300, 175));

		JPanel buttonPane = new JPanel();
		buttonPane.add(changeButton);
		buttonPane.add(cancelButton);
		setButtonActions(this);

		JPanel formPane = new JPanel(new GridLayout(4, 2));
		JLabel playerName = new JLabel("Player Name:");
		JLabel teamNames = new JLabel("Teams:");
		JLabel leagueName = new JLabel("League Name:");
		JLabel sportType = new JLabel("Sport Type:");

		playerField = new JTextField(25);
		teams = new JComboBox(DBteams);
		leagueField = new JTextField(25);
		sportField = new JTextField(25);

		// TODO Use enriqueDBmagic to make these textFields autoPopulate
		// leagueField.setText( "dataFromTheDB" );
		// sportField.setText( "dataFromTheDB" );
		sportField.setEditable(false);
		leagueField.setEditable(false);

		formPane.add(playerName);
		formPane.add(playerField);

		formPane.add(teamNames);
		formPane.add(teams);

		formPane.add(sportType);
		formPane.add(sportField);

		formPane.add(leagueName);
		formPane.add(leagueField);

		Container contentPane = getContentPane();
		setButtonActions(this);
		contentPane.add(formPane, BorderLayout.CENTER);
		contentPane.add(buttonPane, BorderLayout.SOUTH);

		pack();
	}

	@Override
	protected void setButtonActions(final AutoTeamDialog thisDialog)
	{
		changeButton.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				
				thisDialog.close();
			}
		});

		cancelButton.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				thisDialog.close();
			}
		});
	}
}
